package com.mongo.demo.contorller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mongo.demo.pojo.User;
import com.mongo.demo.service.UserRepository;

@RestController
public class UserContorller {
	
	@Autowired
	private UserRepository userDao;

	@GetMapping("/saveUser")
	public String saveUser() {
		User user=new User();
        user.setId(2l);
        user.setUserName("小明");
        user.setPassWord("fffooo123");
        userDao.saveUser(user);
		return "保存成功";
	}
	@GetMapping("/find")
	public void findUser() {
		User user= userDao.findUserByUserName("小明");
	    System.out.println("user is "+user);
	}
	@GetMapping("/update")
	public String updateUser() {
		User user = new User();
		user.setId(2l);
		user.setUserName("天空");
		user.setPassWord("fffxxxx");
		userDao.updateUser(user);
		return "更新成功";
	}
	@GetMapping("/delete")
	public String deleteUser() {
		 userDao.deleteUserById(1l);
		 return "删除成功";
	}
	
}
